<?php

// 获取资讯分页列表(后台)
// GET information.admin.volist

namespace app\api\resource\information\admin;
use think\Db;
use app\api\lib\Page;

class Volist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['adminLogin'];
    // 描述
    public $_description = '获取资讯分页列表(后台)';
    // 参数
    public $_param  = [
        'page'  => '请求页,默认1',
        'show'  => '请求记录数量,默认10',
        'skey'  => '搜索关键词,标题',
    ];
    // 返回
    public $_return = [
        200 => '获取成功',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1);
        $show  = $request->get('show/d',10);

        $skey  = $request->get('skey/s','','trim');

        $table = 'information';
        $where = '';

        // 搜索标题
        if ( !empty($skey) ) {
            $where['title'] = ['like','%' . $skey . '%'];
        }

        $list = Db::name($table)->where($where)->field('cover,content',true)->order('id desc')->page($page,$show)->select();

        $pagelist = Page::run($table, $page, $show, $where, $list);

        return [200,$pagelist];
    }
}